package com.fzkj.thread.demo8;

// 生产者
public class Producer extends Thread {

    private Market market;

    public Producer(Market market) {
        this.market = market;
    }

    @Override
    public void run() {
        while(true){
            synchronized (market){
                try {
                    if (!market.isEmpty){ // 不为空
                        market.wait();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                // 生产产品
                System.out.println("生产产品。。。。。。。。");
                market.setEmpty(false);
                market.notify(); // 唤醒market这个共享对象上的其他等待线程
            }

            try{
                Thread.sleep(1000);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
